/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package beans;

import dbs.Friend;
import dbs.User;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;

/**
 *
 */
@Stateless
@LocalBean
public class GetFriendListBean {

    @EJB
    private UserFacade userFacade;
    
    @EJB
    private FriendFacade friendFacade;
    
    public List<Map<String, Object>> getFriendList(long facebookId)
    {
        List<Friend> friendList = friendFacade.findFriendDataList(facebookId);
        
        List<Map<String, Object>> out = new ArrayList<Map<String, Object>>();
        
        for(Friend friend : friendList)
        {
            User friendUserData = userFacade.findUser(friend.getFriendPK().getFriendId());
            
            if(friendUserData == null)
            {
                // connat find. skip
                continue;
            }
            
            Map<String, Object> friendData = new HashMap<String, Object>();
            
            friendData.put("userID", friend.getFriendPK().getFriendId());
            friendData.put("userName", friendUserData.getName());
            friendData.put("followFlag", friend.getFollowingFlag() == 1 );
            
            out.add(friendData);
        }
        
        return out;
    }
}
